import { reqAddOrUpdateShopCart, reqGoodsInfo } from "@/api"
//封装游客身份模块uuid-->生成一个字符串（不能再变化）
import {getUUID} from '@/utils/uuid_token'
const state={
    goodsInfo:{},
    uuid_token:getUUID()
}
const mutations={
    GETGOODSINFO(state,goodsInfo){
        state.goodsInfo=goodsInfo
    }
}
const actions={
    async getGoodsInfo({commit},skuId){
        const result= await reqGoodsInfo(skuId)
        //console.log(result);
        if(result.code==200){
            commit('GETGOODSINFO',result.data)
        }
    },
    //将产品添加到购物车中
    async addOrUpdateShopCart({commit},{skuId,skuNum}){
        let result = await reqAddOrUpdateShopCart(skuId,skuNum)
    }
}
const getters={
    categoryView:state=>state.goodsInfo.categoryView||{},
    skuInfo:state=>state.goodsInfo.skuInfo||{},
    spuSaleAttrList:state=>state.goodsInfo.spuSaleAttrList||[]
}
export default {
    state,
    mutations,
    actions,
    getters
}